# -*- coding: utf-8 -*- 
from django.db import models
#from intraorg.dict.models import *
from intraorg.members.models import *
#from intraorg.projects.models import *
#from intraorg.groups.models import *

class Contact(models.Model):
    name = models.CharField(verbose_name="Nazwa kontaktu",maxlength=20)    
    description = models.CharField(verbose_name="Opis kontaktu",maxlength=50)    
    def __unicode__(self):
      return self.name
    class Meta:
        verbose_name = u'kontakt'
        verbose_name_plural = u'kontaky'
    class Admin:
        list_display = ("name","description")
        search_fields = ['about','insterests']
    def get_absolute_url(self):
        return "/contacts/%i/" % self.id

class Person(models.Model):
    name = models.CharField(verbose_name="imie i nazwisko",maxlength=40,core=True)    
    position = models.CharField(verbose_name="stanowisko",maxlength=20)    
    responsibilities = models.CharField(verbose_name="odpowiedzialnosc",maxlength=50)    
    email = models.EmailField()
    phone = models.CharField(verbose_name="numer telefonu",maxlength=15)    
    other = models.TextField()
    contact = models.ForeignKey(Contact, unique=True, edit_inline=models.TABULAR, num_in_admin=1)
    def __unicode__(self):
      return self.name
    class Meta:
        verbose_name = u'pracownik'
        verbose_name_plural = u'pracownicy'
    class Admin:
        list_display = ("name","position")
        search_fields = ['position','responsibilities','other']
  
class Url(models.Model):
  name = models.CharField(verbose_name="nazwa strony",maxlength=40,blank=True,null=True,core=True)    
  url = models.URLField()
  desc = models.TextField(verbose_name="opis strony")
  count = models.IntegerField()
  contact = models.ForeignKey(Contact, edit_inline=models.TABULAR, num_in_admin=2)
  def link():
    return u'<a href="%s" target="new">%s</a>' % (self.url,self.name)
  def __unicode__(self):
    return self.name
  class Meta:
      verbose_name = u'strona'
      verbose_name_plural = u'strony'
  class Admin:
      list_display = ("name","url","link")
      search_fields = ["url",'name','desc']

class Issue(models.Model):
  name = models.CharField(verbose_name="nazwa sprawy",maxlength=40)    
  desc = models.TextField(verbose_name="opis sprawy",help_text="Opisz czego dotyczy ta sprawa")
  date = models.DateTimeField(u'data wprowadzenia sprawy',auto_now_add=True)
  def __unicode__(self):
    return self.name
  class Meta:
    verbose_name = u'sprawa'
    verbose_name_plural = u'sprawy'
  class Admin:
      list_display = ("name",'date')
      search_fields = ['name','desc']
  
class IssueCall(models.Model):
  issue = models.ForeignKey(Issue, edit_inline=models.TABULAR, num_in_admin=1,core=True)
  member = models.ForeignKey(Member, edit_inline=models.TABULAR, num_in_admin=1)
  contact = models.ForeignKey(Contact, edit_inline=models.TABULAR, num_in_admin=1)
  date = models.DateTimeField(u'data kontaktu',auto_now_add=True)
  desc = models.TextField(verbose_name="opis kontaktu",help_text="Opisz jakie postanowienia zostały poczynione, kiedy jest data następnego kontaktu oraz wszystko co uważasz za stosowne.")
  def __unicode__(self):
    return u" ".join([self.issue,self.dat])
  class Meta:
    verbose_name = u'kontakt'
    verbose_name_plural = u'kontakty'
  class Admin:
    list_display = ("issue",'member','contact')
    search_fields = ['issue','desc']
  
  
  